package cc.ycws.api.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.annotation.Resource;

import cc.ycws.core.domain.Pay;
import cc.ycws.core.service.PayService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/ssm/paycontroller")
public class PayApi {

    @Resource
    PayService payService;

    @RequestMapping("/show")
    public String show(String address, ModelMap map) throws Exception {
        String addr = new String(address.getBytes("ISO-8859-1"), "utf-8");
        List<Pay> list = payService.show(addr);
        double total = 0.00;
        for (Pay p : list) {
            total = p.getMoeny() * 0.01 + total;
            double moeny = p.getMoeny() * 0.01;
            p.setMoeny(getInt(moeny));
        }
        map.addAttribute("list", list);
        map.addAttribute("total", total);
        return "showpayrecord";
    }

    public static int getInt(double number) {
        BigDecimal bd = new BigDecimal(number).setScale(0, BigDecimal.ROUND_HALF_UP);
        return Integer.parseInt(bd.toString());
    }
}
